<?

class GeneralMedia extends db {

	var $areaObject;
	
	function setAreaObject(&$obj) {
		$this->areaObject = $obj;
	}
	
	function validateMediaOperation($opType = "ADD", $mediaObject = null) {
		$e = new Error();
		// called automatically by the m2 functions that add media, when passed the object
		// opType allows us to distinguish between adding, editing, updating, etc... but most times
		// the same check will work for all operation types
		if ($opType == "UPDATEINFO") {
			if (!User::isAdmin()) {
				$e->add("Only an admin user may edit media areas.");
				return $e;
			}
		}
		
		if ($opType == "RESCAN") {
			if (!User::isAdmin()) {
				$e->add("Only an admin user may rescan media.");
				return $e;
			}
		}
		
		if (!$this->areaObject->isGeneralMedia()) {
			$e->add("You cannot directly move or edit an area that is not generally accessible.");
			return $e;
		} else {
			if (!User::isAdmin()) {
				$e->add("Only an admin user may modify general media.");
				return $e;
			}
		}
		
		// if we get this far...
		return true;
	}
	
}


?>